Database Migration Guide
MongoDB Atlas to MongoDB Production Servers
Migrating a database from MongoDB Atlas to your own production servers involves several steps to ensure a smooth transition. The following guide provides a detailed walkthrough of the process, ensuring you can complete the migration successfully.
Clone External Database using mongodump
- Connect to your MongoDB Atlas database using the appropriate credentials.
- Open a terminal or command prompt.
- Navigate to the directory where you want to save the backup.
- Run the following command to perform a backup:This command will create a backup of your Atlas database in BSON format.
mongodump --uri="<Atlas Connection String>"
Establish VPN Connection for Production
- Ensure you have the necessary VPN client software installed.
- Connect to your production environment via VPN to establish a secure connection.
Connect to Production MongoDB Server
- Open a terminal or command prompt on your local machine.
- Connect to your production MongoDB server using the following command:
mongo --host <production_host> --port <production_port> -u <username> -p
Backup Existing Production Server Database
- Once connected to the production MongoDB server, initiate a backup using the following command:
mongodump --uri="mongodb+srv://<username>:<Password>@<Cluster>.mongodb.net/<Database_name>?retryWrites=true&w=majority"
Remove the Existing Production Database
- Still connected to the production MongoDB server, drop the existing database:
use <production_db_name>
db.dropDatabase()
Restore Cloned Database to Production Server
- In the same terminal, navigate to the directory where you saved the backup created from Atlas.
- Run the following command to restore the backup to the production server:
mongorestore --uri="mongodb://<IP-address>:27017" --nsFrom="<database-name.*>" --nsTo="<newdbname.*>" dump
Update URLs and Production Settings
- In the application code or configuration files, update any URLs and settings that point to the MongoDB Atlas instance. Replace them with the appropriate details for your production server.
Test Everything
- Run thorough testing on your application to ensure that it is functioning as expected with the new production MongoDB server.
- Test various functionalities, endpoints, and queries to verify the integrity of the migrated data and the application's behavior.